/*
 * @lc app=leetcode.cn id=1367 lang=javascript
 *
 * [1367] 二叉树中的列表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {ListNode} head
 * @param {TreeNode} root
 * @return {boolean}
 */

var isMatch = function(head, root){
  if(!head) return true;
  if(!root) return false;
  if(root.val != head.val) return false;
  return isMatch(head.next, root.left) || isMatch(head.next, root.right);
}
var isSubPath = function(head, root) {
  if(!head) return true;
  if(!root) return false;
  if(head.val == root.val && isMatch(head, root)) return true;
  return isSubPath(head, root.left) || isSubPath(head, root.right)
};

// XXXXXX错误，没找到原因
// var isMatch = function(head, root){
//   console.log('aaaa', head.val)
//   if(!head) return true;
//   if(!root) return false;
//   if(head.val != root.val) return false;
//   console.log(head.next.val, root.left.val)
//   return isMatch(head.next, root.left) || isMatch(head.next, root.right);
// }
// var isSubPath = function(head, root) {
//   if(!head) return true;
//   if(!root) return false;
//   if(isMatch(head, root)) return true;
//   if(isMatch(head, root.left) || isMatch(head, root.right)) return true;
//   return false;
// };
// @lc code=end

